from config import WMS_API
from fixture import *

class Test(WMS_API):

    def __init__(self,url):
        super().__init__(url)


    def login(self):
        endpoint = "/jeewms/loginController.do?checkuser"
        data = {
            "userName": "admin",
            "password": "llg123",
            "randCode": "9581",
            "langCode":"zh-cn",
            "orgId":""
        }
        headers = {
            "cookie": "JSESSIONID=D927456B2BA8E5D0716A99BA7FA06067"
        }
        a = self.post_data(endpoint,data,headers)
        return a.json()

    def add_01(self,adb,headers):
        endpoint = "/jeewms/baPlatformController.do?doAdd"
        data = {
            "id":"",
            "platformCode":f"{adb}",
            "platformName":"10011"
        }
        headers = headers
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <=0.6
        logging.info(a.json())
        return a.json()

    def add_02(self):
        endpoint = "/jeewms/baPlatformController.do?doAdd"
        data = {
            "id":"",
            "platformCode":"123456",
            "platformName":"10011"
        }
        headers = {
            "cookie": "JSESSIONID=D927456B2BA8E5D0716A99BA7FA06067"
        }
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <= 0.6
        return a.json()

    def add_03(self):
        endpoint = "/jeewms/baPlatformController.do?doAdd"
        data = {
            "id":"",
            "platformName":"10011"
        }
        headers = {
            "cookie": "JSESSIONID=D927456B2BA8E5D0716A99BA7FA06067"
        }
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <= 0.6
        return a.json()

    def add_04(self):
        endpoint = "/jeewms/baPlatformController.do?doAdd"
        data = {
            "id":"",
            "platformCode":"adb",
        }
        headers = {
            "cookie": "JSESSIONID=D927456B2BA8E5D0716A99BA7FA06067"
        }
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <= 0.6
        return a.json()
    def add_05(self):
        endpoint = "/jeewms/baPlatformController.do?doAdd"
        data = {
            "id":"",
            "platformCode":"adb",
            "platformName":"许归途"
        }
        headers = {
            "cookie": "JSESSIONID=D927456B2BA8E5D0716A99BA7FA06067"
        }
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <= 0.6
        return a.json()

    def update_01(self):
        endpoint = "/jeewms/baPlatformController.do?doUpdate"
        data = {
            "id": "2c9efaca98b2815401992c3ab83a0cfe",
            "platformCode": "adb",
            "platformName": "10011"
        }
        headers = {
            "cookie": "JSESSIONID=D927456B2BA8E5D0716A99BA7FA06067"
        }
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <= 0.6
        return a.json()

    def update_02(self):
        endpoint = "/jeewms/baPlatformController.do?doUpdate"
        data = {
            "id": "2c9efaca98b2815401992c3ab83a0cfe",
            "platformCode": "adb",
            "platformName": "10011"
        }
        headers = {
            "cookie": "JSESSIONID=D927456B2BA8E5D0716A99BA7FA06067"
        }
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <= 0.6
        return a.json()

    def update_03(self,adb,header):
        endpoint = "/jeewms/baPlatformController.do?doUpdate"
        data = {
            "id": "2c9efaca98b2815401992c3ab83a0cfe",
            "platformCode": f"{adb}",
            "platformName": "10011"
        }
        headers = header
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <= 0.6
        return a.json()

    def update_04(self):
        endpoint = "/jeewms/baPlatformController.do?doUpdate"
        data = {
            "id": "2c9efaca98b2815401992c3ab83a0cfe",
            "platformCode": "adb",
            "platformName": "10011"
        }
        headers = {
            "cookie": "JSESSIONID=D927456B2BA8E5D0716A99BA7FA06067"
        }
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <= 0.6
        return a.json()

    def update_05(self):
        endpoint = "/jeewms/baPlatformController.do?doUpdate"
        data = {
            "id": "2c9efaca98b2815401992c3ab83a0cfe",
            "platformCode": "adb",
            "platformName": "10011"
        }
        headers = {
            "cookie": "JSESSIONID=D927456B2BA8E5D0716A99BA7FA06067"
        }
        a = self.post_data(endpoint, data, headers)
        assert 'msg' in a.json()
        assert a.status_code == 200
        assert a.elapsed.total_seconds() <= 0.6
        return a.json()

@pytest.mark.parametrize('data',yaml_loc())
def test_01(data,log):
    url = "http://47.113.229.131:9080"
    wms = Test(url)
    res = wms.login()
    print(res)
    logging.info(res)
    res1 = wms.add_01(data['platformCode'],log)
    print(res1)
    logging.info(res1)
    res2 = wms.add_02()
    print(res2)
    logging.info(res2)
    res3 = wms.add_03()
    print(res3)
    logging.info(res3)
    res4 = wms.add_04()
    print(res4)
    logging.info(res4)
    res5 = wms.add_05()
    print(res5)
    logging.info(res5)
    rea = wms.update_01()
    print(rea)
    logging.info(rea)
    rea1 = wms.update_02()
    print(rea1)
    logging.info(rea1)
    rea2 = wms.update_03(data['platformCode'],log)
    print(rea2)
    logging.info(rea2)
    rea3 = wms.update_04()
    print(rea3)
    logging.info(rea3)
    rea4 = wms.update_05()
    print(rea4)
    logging.info(rea4)